package cn.wd.user.controller;


import cn.wd.common.vo.R;
import cn.wd.user.domain.entity.LoginLog;
import cn.wd.user.qo.LoginLogPage;
import cn.wd.user.service.ILoginLogService;
import cn.wd.user.vo.JsonResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/loginLog")
public class LoginLogController {

    private final ILoginLogService loginLogService;

    public LoginLogController(ILoginLogService loginLogService) {
        this.loginLogService = loginLogService;
    }

    @RequestMapping("/list")
    public R<Page<LoginLog>> listLoginLogPage(LoginLogPage qo) {
        return R.OK(loginLogService.listLoginLogPage(qo));
    }

    @RequestMapping("/saveOrUpdate")
    public JsonResult<?> saveOrUpdate(@RequestBody LoginLog loginLog) {
        if (loginLog.getId() != null) {
            loginLogService.updateById(loginLog);
        } else {
            loginLogService.save(loginLog);
        }

        return JsonResult.success();
    }

    @RequestMapping("/delete")
    public JsonResult<?> delete(Long id) {
        if (id == null) {
            return JsonResult.failed("删除的 id 不能为空!");
        }

        loginLogService.removeById(id);
        return JsonResult.success();
    }

    @RequestMapping("/batchDelete")
    public JsonResult<?> batchDelete(@RequestBody(required=false) Long[] deletedIds) {
        loginLogService.batchDelete(deletedIds);
        return JsonResult.success();
    }
}
